package threadTest.volatileTest;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * 功能描述: volatile 特性1 可见性, 多个线程同时访问同一个变量，修改变量的值，
 *       main 线程初始化 num = 0;
 *       修改变量num的线程 输出变量num,且设置num = 10;
 *       main 线程输出变量num 为10
 * 2024/03/12
 * <p>
 * ZhangYi
 */
public class VolatileTest01 {

    private static volatile int num = 0;

    private static int num2 = 0;

    public static void main(String[] args) {
        new Thread(()->{
            if (num ==0){
                String.format("num 的值为%d" , num);

                num +=10;
            }
        },"修改变量num的线程").start();


        while (Thread.activeCount()>2){
            Thread.yield();
        }

        System.out.println(String.format("num的值 %d, num2 的值 %d",num,num2));
    }
}
